package org.neuedu.aop;

import com.alibaba.fastjson.JSONObject;
import jakarta.annotation.Resource;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.neuedu.entity.Employee;
import org.neuedu.mq.NeuMail;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AdminAop {

    @Resource
    RabbitTemplate rabbitTemplate;

    @AfterReturning(value="execution(public * org.neuedu.service.impl.EmployeeServiceImpl.add(..))")
    public void EmpAddAfter(JoinPoint joinPoint){
        final Object[] args=joinPoint.getArgs();
        String to=args[5].toString();
        String subject="HITS云医院系统消息";
        String text=String.format("""
                <h2>欢迎：%s</h2>
                <p>HIS智慧医院系统已为您创建了用户，登录名为:%s,密码为:%s</p>
                """,args[3].toString(),args[4].toString(),args[6].toString());
        rabbitTemplate.convertAndSend("lzwexchange","admin", JSONObject.toJSONString(new NeuMail(to,subject,text)));
    }
    @AfterReturning(value="execution(public * org.neuedu.service.impl.EmployeeServiceImpl.updateEmpById(..))")
    public void EmpUpdateAfter(JoinPoint joinPoint){
        System.out.println("dsadas");
        final Object[] args=joinPoint.getArgs();
        Employee employee= (Employee) args[0];
        System.out.println(employee);
//        String to=employee.getEmail();
//        String subject="HITS云医院系统消息";
//        String text=String.format("""
//                <h2>欢迎：%s</h2>
//                <p>HIS智慧医院系统密码已修改，登录名为:%s,密码为:%s</p>
//                """,employee.getRealname(),employee.getPhone(),employee.getPassword());
//        rabbitTemplate.convertAndSend("lzwexchange","admin", JSONObject.toJSONString(new NeuMail(to,subject,text)));
    }
}
